import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:getx/config/resource/assets_images.dart';
import 'package:getx/config/theme/app_style.dart';
import 'package:getx/view_models/login/login_view_model.dart';

class LoginView extends GetView<LoginViewModel> {
  const LoginView({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        decoration: BoxDecoration(
          image: DecorationImage(image: AssetImage(AssetsImages.loginBg), fit: BoxFit.cover),
        ),
        padding: AppStyle.defaultPadding,
        child: Form(
          key: controller.loginFormKey,
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            spacing: 10,
            children: [
              SizedBox(height: MediaQuery.of(context).padding.top),
              Text('登录', style: TextStyle(fontSize: 48, fontWeight: FontWeight.bold)),
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [Text('还没有账号？'), TextButton(onPressed: () {}, child: Text('去注册'))],
              ),
              TextFormField(
                controller: controller.emailController,
                decoration: InputDecoration(
                  hintText: '请输入邮箱',
                  labelText: '邮箱',
                  prefixIcon: Icon(Icons.account_box_sharp),
                ),
                validator: controller.validatorUserName,
              ),
              TextFormField(
                controller: controller.passwordController,
                obscureText: true,
                obscuringCharacter: "*",
                decoration: InputDecoration(
                  hintText: '请输入密码',
                  labelText: '密码',
                  prefixIcon: Icon(Icons.password_sharp),
                ),
                validator: controller.validatorPassword,
              ),
              ElevatedButton(
                onPressed: controller.login,
                style: ElevatedButton.styleFrom(
                  minimumSize: Size(double.infinity, kMinInteractiveDimension),
                ),
                child: Text('登录'),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
